package gui;

import java.util.Date;

import gui.treenodes.TransactionNode;
import gui.treenodes.TransactionTreeNode;

import org.netbeans.swing.outline.RowModel;

import core.Transaction;

public class TransactionRowModel implements RowModel
{
	@Override public Class<?> getColumnClass(int columnIndex){
		Class<?> toReturn = null;
		switch(columnIndex){
		case 0: toReturn = Date.class;
			break;
		case 1: toReturn = Double.class;
			break;
		}
		return toReturn;
	}
	
	@Override public int getColumnCount(){
		return 2;
	}

	@Override public String getColumnName(int columnIndex){
		String name = null;
		switch(columnIndex){
		case 0: name = "Datum";
			break;
		case 1: name = "Částka";
			break;
		}
		return name;
	}

	@Override public Object getValueFor(Object node, int column){
		Object toReturn = null;
		switch (column){
		case 0:
			if(node instanceof TransactionNode){
				toReturn = ((TransactionNode)node).getTransaction().getDate();
			}
			break;
		case 1:
			toReturn = ((TransactionTreeNode)node).getAmmount();
			break;
		}
		return toReturn;
	}

	@Override public boolean isCellEditable(Object node, int column){
		return node instanceof TransactionNode;
	}

	@Override public void setValueFor(Object node, int column, Object value){
		Transaction transaction = ((TransactionNode)node).getTransaction();
		if(column == 0){
			System.out.println((Date)value);
			transaction.setDate((Date)value);
		}
		else if(column == 1){
			transaction.setAmmount((Double)value);
		}
	}
}
